package general;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @Author if
 * @Description: 单向消息生产者
 * @Date 2021-10-24 下午 07:21
 */
public class OneWayProducer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException {
        DefaultMQProducer producer=new DefaultMQProducer("pg");
        producer.setNamesrvAddr("centos:9876");
        producer.start();

        for(int i=0;i<100;i++){
            byte[] body=("Hi,"+i).getBytes();
            Message msg=new Message("OneWayTopic","OneWayTopic",body);
            //单向发送
            producer.sendOneway(msg);
        }
        producer.shutdown();
        System.out.println("producer shutdown");
    }
}
